﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace EventLesson
{
    /// <summary>
    /// DragDropEventWindow1.xaml 的交互逻辑
    /// </summary>
    public partial class DragDropEventWindow1 : Window
    {
        public DragDropEventWindow1()
        {
            InitializeComponent();
        }

        private void StackPanel_DragEnter(object sender, DragEventArgs e)
        {
            (sender as StackPanel).Background = Brushes.Green;
        }

        private void StackPanel_DragLeave(object sender, DragEventArgs e)
        {

            (sender as StackPanel).Background = Brushes.Transparent;
        }

        private void StackPanel_DragOver(object sender, DragEventArgs e)
        {

        }

        private void StackPanel_Drop(object sender, DragEventArgs e)
        {
            var str = e.Data.GetData(typeof(string)).ToString();
            Brush brush = (Brush)new BrushConverter().ConvertFromString(str);
            (sender as StackPanel).Children.Add(new Border { Height = 30, Background = brush });
        }

        private void Border_MouseLeftButtonDown_1(object sender, MouseButtonEventArgs e)
        {
            Border border = sender as Border;
            //开始一个拖动处理  准备相关数据
            DragDrop.DoDragDrop(border, border.Background.ToString(), DragDropEffects.Copy);
        }
    }
}
